home *** CD-ROM | disk | FTP | other *** search
/ Risc World 5 / Risc World 5.iso / SOFTWARE / Issue3 / Games / xrick / !xrick / src / c / scr_imap < prev    next >
Text File  |  2004-06-24  |  5KB  |  300 lines

  1. /*
  2.  * xrick/src/scr_imap.c
  3.  *
  4.  * Copyright (C) 1998-2002 BigOrno (bigorno@bigorno.net). All rights reserved.
  5.  *
  6.  * The use and distribution terms for this software are contained in the file
  7.  * named README, which can be found in the root of this distribution. By
  8.  * using this software in any fashion, you are agreeing to be bound by the
  9.  * terms of this license.
  10.  *
  11.  * You must not remove this notice, or any other, from this software.
  12.  */
  13.  
  14. #include <stdio.h>
  15.  
  16. #include "system.h"
  17. #include "game.h"
  18. #include "screens.h"
  19.  
  20. #include "rects.h"
  21. #include "draw.h"
  22. #include "control.h"
  23. #include "maps.h"
  24.  
  25. /*
  26.  * local vars
  27.  */
  28. static U16 step;              /* current step */
  29. static U16 count;             /* number of loops for current step */
  30. static U16 run;               /* 1 = run, 0 = no more step */
  31. static U8 flipflop;           /* flipflop for top, bottom, left, right */
  32. static U16 spnum;             /* sprite number */
  33. static U16 spx, spdx;         /* sprite x position and delta */
  34. static U16 spy, spdy;         /* sprite y position and delta */
  35. static U16 spbase, spoffs;    /* base, offset for sprite numbers table */
  36. static U8 seq = 0;            /* anim sequence */
  37.  
  38. static rect_t anim_rect = { 120, 16, 64, 64, NULL }; /* anim rectangle */
  39.  
  40. /*
  41.  * prototypes
  42.  */
  43. static void drawtb(void);
  44. static void drawlr(void);
  45. static void drawsprite(void);
  46. static void drawcenter(void);
  47. static void nextstep(void);
  48. static void anim(void);
  49. static void init(void);
  50.  
  51. /*
  52.  * Map introduction
  53.  *
  54.  * ASM: 1948
  55.  *
  56.  * return: SCREEN_RUNNING, SCREEN_DONE, SCREEN_EXIT
  57.  */
  58. U8
  59. screen_introMap(void)
  60. {
  61.   switch (seq) {
  62.   case 0:
  63.     sysvid_clear();
  64.  
  65. #ifdef GFXPC
  66.     draw_tilesBank = 1;
  67.     draw_filter = 0xAAAA;
  68. #endif
  69. #ifdef GFXST
  70.     draw_tilesBank = 0;
  71. #endif
  72.     draw_tllst = screen_imaptext[game_map];
  73.     draw_setfb(32, 0);
  74.     draw_tilesSubList();
  75.  
  76.     draw_setfb(32, 96);
  77. #ifdef GFXPC
  78.     draw_filter = 0x5555;
  79. #endif
  80.     draw_tilesList();
  81.  
  82.     game_rects = NULL;
  83.  
  84. #ifdef GFXPC
  85.     draw_filter = 0xFFFF;
  86. #endif
  87.  
  88.     init();
  89.     nextstep();
  90.     drawcenter();
  91.     drawtb();
  92.     drawlr();
  93.     drawsprite();
  94.     control_last = 0;
  95.  
  96.     game_rects = &draw_SCREENRECT;
  97.  
  98. #ifdef ENABLE_SOUND
  99.     game_setmusic(map_maps[game_map].tune, 1);
  100. #endif
  101.  
  102.     seq = 1;
  103.     break;
  104.   case 1:  /* top and bottom borders */
  105.     drawtb();
  106.     game_rects = &anim_rect;
  107.     seq = 2;
  108.     break;
  109.   case 2:  /* background and sprite */
  110.     anim();
  111.     drawcenter();
  112.     drawsprite();
  113.     game_rects = &anim_rect;
  114.     seq = 3;
  115.     break;
  116.   case 3:  /* all borders */
  117.     drawtb();
  118.     drawlr();
  119.     game_rects = &anim_rect;
  120.     seq = 1;
  121.     break;
  122.   case 4:  /* wait for key release */
  123.     if (!(control_status & CONTROL_FIRE))
  124.       seq = 5;
  125.     else
  126.       sys_sleep(50); /* .5s */
  127.     break;
  128.   }
  129.  
  130.   if (control_status & CONTROL_FIRE) {  /* end as soon as key pressed */
  131.     seq = 4;
  132.   }
  133.  
  134.   if (control_status & CONTROL_EXIT)  /* check for exit request */
  135.     return SCREEN_EXIT;
  136.  
  137.   if (seq == 5) {  /* end as soon as key pressed */
  138.     sysvid_clear();
  139.     seq = 0;
  140.     return SCREEN_DONE;
  141.   }
  142.   else
  143.     return SCREEN_RUNNING;
  144. }
  145.  
  146.  
  147. /*
  148.  * Display top and bottom borders (0x1B1F)
  149.  *
  150.  */
  151. static void
  152. drawtb(void)
  153. {
  154.   U8 i;
  155.  
  156.   flipflop++;
  157.   if (flipflop & 0x01) {
  158.     draw_setfb(128, 16);
  159.     for (i = 0; i < 6; i++)
  160.       draw_tile(0x40);
  161.     draw_setfb(128, 72);
  162.     for (i = 0; i < 6; i++)
  163.       draw_tile(0x06);
  164.   }
  165.   else {
  166.     draw_setfb(128, 16);
  167.     for (i = 0; i < 6; i++)
  168.       draw_tile(0x05);
  169.     draw_setfb(128, 72);
  170.     for (i = 0; i < 6; i++)
  171.       draw_tile(0x40);
  172.   }
  173. }
  174.  
  175.  
  176. /*
  177.  * Display left and right borders (0x1B7C)
  178.  *
  179.  */
  180. static void
  181. drawlr(void)
  182. {
  183.   U8 i;
  184.  
  185.   if (flipflop & 0x02) {
  186.     for (i = 0; i < 8; i++) {
  187.       draw_setfb(120, 16 + i * 8);
  188.       draw_tile(0x04);
  189.       draw_setfb(176, 16 + i * 8);
  190.       draw_tile(0x04);
  191.     }
  192.   }
  193.   else {
  194.     for (i = 0; i < 8; i++) {
  195.       draw_setfb(120, 16 + i * 8);
  196.       draw_tile(0x2B);
  197.       draw_setfb(176, 16 + i * 8);
  198.       draw_tile(0x2B);
  199.     }
  200.   }
  201. }
  202.  
  203.  
  204. /*
  205.  * Draw the sprite (0x19C6)
  206.  *
  207.  */
  208. static void
  209. drawsprite(void)
  210. {
  211.   draw_sprite(spnum, 128 + ((spx << 1) & 0x1C), 24 + (spy << 1));
  212. }
  213.  
  214.  
  215. /*
  216.  * Draw the background (0x1AF1)
  217.  *
  218.  */
  219. static void
  220. drawcenter(void)
  221. {
  222.   static U8 tn0[] = { 0x07, 0x5B, 0x7F, 0xA3, 0xC7 };
  223.   U8 i, j, tn;
  224.  
  225.   tn = tn0[game_map];
  226.   for (i = 0; i < 6; i++) {
  227.     draw_setfb(128, (24 + 8 * i));
  228.     for (j = 0; j < 6; j++)
  229.       draw_tile(tn++);
  230.   }
  231. }
  232.  
  233.  
  234. /*
  235.  * Next Step (0x1A74)
  236.  *
  237.  */
  238. static void
  239. nextstep(void)
  240. {
  241.   if (screen_imapsteps[step].count) {
  242.     count = screen_imapsteps[step].count;
  243.     spdx = screen_imapsteps[step].dx;
  244.     spdy = screen_imapsteps[step].dy;
  245.     spbase = screen_imapsteps[step].base;
  246.     spoffs = 0;
  247.     step++;
  248.   }
  249.   else {
  250.     run = 0;
  251.   }
  252. }
  253.  
  254.  
  255. /*
  256.  * Anim (0x1AA8)
  257.  *
  258.  */
  259. static void
  260. anim(void)
  261. {
  262.   U16 i;
  263.  
  264.   if (run) {
  265.     i = screen_imapsl[spbase + spoffs];
  266.     if (i == 0) {
  267.       spoffs = 0;
  268.       i = screen_imapsl[spbase];
  269.     }
  270.     spnum = i;
  271.     spoffs++;
  272.     spx += spdx;
  273.     spy += spdy;
  274.     count--;
  275.     if (count == 0)
  276.       nextstep();
  277.   }
  278. }
  279.  
  280.  
  281. /*
  282.  * Initialize (0x1A43)
  283.  *
  284.  */
  285. static void
  286. init(void)
  287. {
  288.   run = 0; run--;
  289.   step = screen_imapsofs[game_map];
  290.   spx = screen_imapsteps[step].dx;
  291.   spy = screen_imapsteps[step].dy;
  292.   step++;
  293.   spnum = 0; /* NOTE spnum in [8728] is never initialized ? */
  294. }
  295.  
  296. /* eof */
  297.  
  298.  
  299.  
  300.